{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "47102c82-3530-43e1-bd06-c579d59e8bc7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.5, 1.3, 7.5],\n",
       "       [5.6, 7.8, 1.2]])"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "fang_array = np.array([[1.5,1.3,7.5],\n",
    "                       [5.6,7.8,1.2]])\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "638a660c-6584-4cd5-98ff-e91a8154b882",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.3, 1.5, 7.5],\n",
       "       [1.2, 5.6, 7.8]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(fang_array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "998544ef-b559-4a58-86de-953834e2281c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1.5, 1.3, 1.2],\n",
       "       [5.6, 7.8, 7.5]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sort(fang_array, axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bc5070c5-8a26-478a-91e1-bbdb14cce7cb",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 0, 2],\n",
       "       [2, 0, 1]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.argsort(fang_array) #排序后得参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e473b947-d3bd-4b40-950e-5fa62d08982d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.        ,  1.11111111,  2.22222222,  3.33333333,  4.44444444,\n",
       "        5.55555556,  6.66666667,  7.77777778,  8.88888889, 10.        ])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.linspace(0, 10, 10)\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3270a482-04ed-4609-8835-c78e1b68fe89",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "values = np.array([2.5, 6.5, 9.5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9b6bb4d9-151b-4c07-bd01-a159e8084ccb",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 6, 9])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.searchsorted(fang_array, values)\n",
    "# 返回插入的数排序在哪个位置\n",
    "# fang_array必须是一个排序好的数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "eb24a48b-496a-4765-a9a4-602ce85de440",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 0, 6],\n",
       "       [1, 7, 0],\n",
       "       [2, 3, 1],\n",
       "       [2, 4, 0]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = np.array([[1,0,6],\n",
    "                       [1,7,0],\n",
    "                       [2,3,1],\n",
    "                       [2,4,0]])\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "f14a2be9-1c70-4d3e-bf4b-ee14abbba8c3",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 1, 2, 0])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "index = np.lexsort([-1*fang_array[:,0], fang_array[:,2]])\n",
    "index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "183a9de2-072c-4feb-b604-09414dd1c21c",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 4, 0],\n",
       "       [1, 7, 0],\n",
       "       [2, 3, 1],\n",
       "       [1, 0, 6]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fang_array = fang_array[index]\n",
    "fang_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a4f6f67-c452-4f30-b9ca-5ffa00fa3aa6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
